package cn.xeblog.plugin.game.sudoku.enums;

import com.intellij.openapi.ui.ComboBox;
import java.awt.Dimension;
import java.util.Arrays;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 实时提示
 *
 * @author ☆程序员鼓励师☆
 * @date 2022/8/17 16:58
 */
@Getter
@AllArgsConstructor
public enum RealTimeTip {
  /**
   * 开启
   */
  ENABLE(true, "是"),
  /**
   * 未开启
   */
  DIS_ENABLE(false, "否");

  /**
   * 开启
   */
  private final boolean enabled;
  /**
   * 备注
   */
  private final String memo;

  /**
   * 通过备注获取实时提示枚举
   *
   * @param name 备注名称
   * @return 实时提示枚举
   */
  public static RealTimeTip getRealTimeTip(String name) {
    return Arrays.stream(values()).filter(realTimeTip -> realTimeTip.memo.equals(name)).findFirst()
        .orElse(RealTimeTip.DIS_ENABLE);
  }

  /**
   * 获取实时提示下拉列表项
   *
   * @param dimension 尺寸
   * @return 实时提示下拉列表项
   */
  public ComboBox<String> getComboBox(Dimension dimension) {
    ComboBox<String> comboBox = new ComboBox<>();
    // 设置此组件的首选大小
    comboBox.setPreferredSize(dimension);
    // 实时提示下拉列表项添加选项值
    Arrays.stream(RealTimeTip.values()).map(RealTimeTip::getMemo).forEach(comboBox::addItem);
    comboBox.setSelectedItem(this.getMemo());
    return comboBox;
  }
}
